home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FFLUSH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  583 b   |  24 lines

  1. /* fflush.c */
  2. #include <stdio.h>
  3. main()
  4. {
  5.      int i;
  6.      char line[81];
  7.      FILE *infile;
  8.             /* Open the file. Note that we need two '\' */
  9.     if ((infile = fopen("c:\\autoexec.bat", "r")) == NULL)
  10.     {
  11.         perror ("fopen failed.\n");
  12.         exit(0);
  13.     }
  14.             /* Now read characters using fgetc */
  15.     for (i=0; i<80; i++)
  16.     {
  17.        line[i] = fgetc(infile);
  18.        if (i==4) fflush(infile); /* Flush buffer */
  19.        if (line[i] == '\n') break;
  20.     }
  21.     line[i+1] = '\0';                 /* Mark end of string */
  22.                 /* Now print the line and see how it looks */
  23.     printf("The line is: %s", line);
  24. }